{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Imports\n",
    "\n",
    "Import all the modules and functionalities we need."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "# Import standard libraries.\n",
    "import os\n",
    "\n",
    "# Import third party libraries.\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "\n",
    "# Import custom libraries/scripts.\n",
    "import annotations\n",
    "import helpers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Loading data\n",
    "\n",
    "Fetch all our relevant data for the current analysis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set working contants.\n",
    "EXPERIMENTS_PATH = r'\\\\10.40.12.80\\home\\PhD\\Results\\Competition\\DL\\small_arenas\\territory\\mating_pairs\\processed'\n",
    "FPS = 60\n",
    "N_MINUTES = 30\n",
    "N_FRAMES = N_MINUTES * 60 * FPS\n",
    "INK = 'black'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set figure configurations.\n",
    "sns.set(\n",
    "        context='paper',\n",
    "        style='ticks',\n",
    "        font='sans-serif',\n",
    "        font_scale=1.0, \n",
    "        rc={\n",
    "            'axes.axisbelow': True,\n",
    "            'axes.edgecolor': INK,\n",
    "            'axes.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'axes.grid': False,\n",
    "            'axes.labelcolor': INK,\n",
    "            'axes.labelsize': 13.0,\n",
    "            'axes.labelweight': 'normal',\n",
    "            'axes.linewidth': 1.0,\n",
    "            'axes.spines.left': True,\n",
    "            'axes.spines.bottom': True,\n",
    "            'axes.spines.top': False,\n",
    "            'axes.spines.right': False,\n",
    "            'axes.titlepad': 15.0,\n",
    "            'axes.titlesize': 20.0,\n",
    "            'axes.titleweight': 'bold',\n",
    "            'figure.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'figure.figsize': [3.0, 4.0],\n",
    "            'figure.titlesize': 30.0,\n",
    "            'figure.titleweight': 'bold',\n",
    "            'font.family': ['sans-serif'],\n",
    "            'font.sans-serif': ['Arial'],\n",
    "            'legend.frameon': False,\n",
    "            'legend.fontsize': 11.0,\n",
    "            'lines.color': INK,\n",
    "            'lines.linewidth': 1.0,\n",
    "            'patch.edgecolor': INK,\n",
    "            'savefig.dpi': 300,\n",
    "            'savefig.format': 'png',\n",
    "            'savefig.bbox': 'tight',\n",
    "            'savefig.transparent': True,\n",
    "            'text.color': INK,\n",
    "            'text.usetex': False,\n",
    "            'xtick.color': INK,\n",
    "            'xtick.direction': 'out',\n",
    "            'xtick.labelsize': 12.0,\n",
    "            'xtick.major.pad': 5.0,\n",
    "            'xtick.major.size': 0.0,\n",
    "            'xtick.major.width': 1.0,\n",
    "            'xtick.minor.size': 0.0,\n",
    "            'xtick.minor.width': 0.4,\n",
    "            'ytick.color': INK,\n",
    "            'ytick.direction': 'out',\n",
    "            'ytick.labelsize': 12.0,\n",
    "            'ytick.major.pad': 5.0,\n",
    "            'ytick.major.size': 3.0,\n",
    "            'ytick.major.width': 1.0,\n",
    "            'ytick.minor.size': 0.0,\n",
    "            'ytick.minor.width': 0.4\n",
    "           }\n",
    "       )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Folder already exists, skipping.\n"
     ]
    }
   ],
   "source": [
    "# Prepare the Figures folder to save our graphs in.\n",
    "savepath = os.path.join(r'C:\\Users\\Miguel\\Desktop\\paper_data', 'paper_figures', 'figure4')\n",
    "try:\n",
    "    os.makedirs(savepath)\n",
    "    print('New folder created.')\n",
    "except FileExistsError:\n",
    "    print('Folder already exists, skipping.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paths to conditions:\n",
      " ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor', '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory']\n"
     ]
    }
   ],
   "source": [
    "# Set the conditions to analyze.\n",
    "condition_order = ['food_odor', 'territory']\n",
    "conditions = [item.path for item in os.scandir(EXPERIMENTS_PATH) if item.name in condition_order]\n",
    "print('Paths to conditions:\\n', conditions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\n",
      " food_odor\n",
      "Copulation too short: video_2022-05-11T11_46_58_arena5.csv\n",
      "\t\n",
      " territory\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'food_odor': ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena9.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena12.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena9.csv'],\n",
       " 'territory': ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena12.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena9.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena9.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena6.csv']}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load all usable experiments for each condition.\n",
    "experiments = {condition: [] for condition in condition_order}\n",
    "\n",
    "for condition_path in conditions:\n",
    "    \n",
    "    condition = os.path.basename(condition_path)\n",
    "    print('\\t\\n', condition)\n",
    "    \n",
    "    for item in os.scandir(condition_path):\n",
    "        if item.name.endswith('.csv'):\n",
    "            \n",
    "            annotation_video = annotations.read(item.path)\n",
    "\n",
    "            try:\n",
    "                copulation = annotation_video[0].events[0]\n",
    "                copulation_duration = copulation.duration\n",
    "\n",
    "                # Filter out videos where copulation is interrupted.\n",
    "                copulation_end = copulation.time_interval[1]\n",
    "                if copulation_end==N_FRAMES and copulation_duration < 5 * 60 * FPS:\n",
    "                    print('Copulation interrupted:', item.name)\n",
    "                    continue\n",
    "\n",
    "                # Filter out videos where copulation lasts less than 8 minutes.\n",
    "                if copulation_duration <= 8 * 60 * FPS:\n",
    "                    print('Copulation too short:', item.name)\n",
    "                    continue\n",
    "            \n",
    "            except IndexError:\n",
    "                continue\n",
    "            \n",
    "            experiments[condition].append(item.path)\n",
    "\n",
    "experiments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Aggression Analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iteration: 0 \n",
      "Experiment: video_2022-05-11T11_12_38_arena10 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2022-05-11T11_12_38_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2022-05-11T11_12_38_arena13 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2022-05-11T11_12_38_arena15 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2022-05-11T11_12_38_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2022-05-11T11_12_38_arena9 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2022-05-11T11_46_58_arena1 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2022-05-11T11_46_58_arena2 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2022-05-11T11_46_58_arena3 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 9 \n",
      "Experiment: video_2022-05-11T11_46_58_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2022-05-11T11_46_58_arena6 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2022-05-11T11_46_58_arena8 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 12 \n",
      "Experiment: video_2022-05-11T12_18_40_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2022-05-11T12_18_40_arena12 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 14 \n",
      "Experiment: video_2022-05-11T12_18_40_arena15 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 15 \n",
      "Experiment: video_2022-05-11T12_18_40_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 16 \n",
      "Experiment: video_2022-05-11T12_18_40_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 17 \n",
      "Experiment: video_2022-05-11T12_18_40_arena7 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 18 \n",
      "Experiment: video_2022-05-11T12_18_40_arena8 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 19 \n",
      "Experiment: video_2022-05-12T10_59_09_arena1 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 20 \n",
      "Experiment: video_2022-05-12T10_59_09_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 21 \n",
      "Experiment: video_2022-05-12T10_59_09_arena15 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 22 \n",
      "Experiment: video_2022-05-12T10_59_09_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 23 \n",
      "Experiment: video_2022-05-12T10_59_09_arena2 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 24 \n",
      "Experiment: video_2022-05-12T10_59_09_arena5 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 25 \n",
      "Experiment: video_2022-05-12T10_59_09_arena6 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 26 \n",
      "Experiment: video_2022-05-12T11_34_40_arena10 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 27 \n",
      "Experiment: video_2022-05-12T11_34_40_arena13 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 28 \n",
      "Experiment: video_2022-05-12T11_34_40_arena14 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 29 \n",
      "Experiment: video_2022-05-12T11_34_40_arena3 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 30 \n",
      "Experiment: video_2022-05-12T11_34_40_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 31 \n",
      "Experiment: video_2022-05-12T11_34_40_arena7 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 32 \n",
      "Experiment: video_2022-05-12T11_34_40_arena9 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 0 \n",
      "Experiment: video_2022-05-11T11_12_38_arena1 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2022-05-11T11_12_38_arena2 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2022-05-11T11_12_38_arena3 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2022-05-11T11_12_38_arena4 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2022-05-11T11_12_38_arena5 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2022-05-11T11_12_38_arena6 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2022-05-11T11_12_38_arena7 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2022-05-11T11_12_38_arena8 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2022-05-11T11_46_58_arena10 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 9 \n",
      "Experiment: video_2022-05-11T11_46_58_arena11 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2022-05-11T11_46_58_arena12 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2022-05-11T11_46_58_arena13 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 12 \n",
      "Experiment: video_2022-05-11T11_46_58_arena14 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2022-05-11T11_46_58_arena15 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 14 \n",
      "Experiment: video_2022-05-11T11_46_58_arena16 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 15 \n",
      "Experiment: video_2022-05-11T11_46_58_arena9 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 16 \n",
      "Experiment: video_2022-05-11T12_18_40_arena1 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 17 \n",
      "Experiment: video_2022-05-11T12_18_40_arena10 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 18 \n",
      "Experiment: video_2022-05-11T12_18_40_arena13 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 19 \n",
      "Experiment: video_2022-05-11T12_18_40_arena14 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 20 \n",
      "Experiment: video_2022-05-11T12_18_40_arena2 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 21 \n",
      "Experiment: video_2022-05-11T12_18_40_arena5 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 22 \n",
      "Experiment: video_2022-05-11T12_18_40_arena6 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 23 \n",
      "Experiment: video_2022-05-11T12_18_40_arena9 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 24 \n",
      "Experiment: video_2022-05-12T10_59_09_arena10 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 25 \n",
      "Experiment: video_2022-05-12T10_59_09_arena13 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 26 \n",
      "Experiment: video_2022-05-12T10_59_09_arena3 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 27 \n",
      "Experiment: video_2022-05-12T10_59_09_arena4 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 28 \n",
      "Experiment: video_2022-05-12T10_59_09_arena7 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 29 \n",
      "Experiment: video_2022-05-12T10_59_09_arena8 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 30 \n",
      "Experiment: video_2022-05-12T11_34_40_arena15 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 31 \n",
      "Experiment: video_2022-05-12T11_34_40_arena16 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 32 \n",
      "Experiment: video_2022-05-12T11_34_40_arena5 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 33 \n",
      "Experiment: video_2022-05-12T11_34_40_arena6 \n",
      "Condition: territory \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>ratio_bouts</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.012222</td>\n",
       "      <td>1.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.018500</td>\n",
       "      <td>1.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.017000</td>\n",
       "      <td>0.8</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.014611</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001833</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T10_59_09_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009833</td>\n",
       "      <td>1.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001222</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>True</td>\n",
       "      <td>0.016889</td>\n",
       "      <td>2.2</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>67 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  ratio_bouts  condition  \\\n",
       "0             True      0.012222          1.6  food_odor   \n",
       "1             True      0.018500          1.4  food_odor   \n",
       "2             True      0.017000          0.8  food_odor   \n",
       "3             True      0.000333          0.2  food_odor   \n",
       "4             True      0.014611          1.2  food_odor   \n",
       "..             ...           ...          ...        ...   \n",
       "62            True      0.001833          0.8  territory   \n",
       "63            True      0.009833          1.8  territory   \n",
       "64            True      0.001222          0.8  territory   \n",
       "65           False      0.000000          0.0  territory   \n",
       "66            True      0.016889          2.2  territory   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-11T11_12_38_arena10  \n",
       "1   video_2022-05-11T11_12_38_arena11  \n",
       "2   video_2022-05-11T11_12_38_arena13  \n",
       "3   video_2022-05-11T11_12_38_arena15  \n",
       "4   video_2022-05-11T11_12_38_arena16  \n",
       "..                                ...  \n",
       "62   video_2022-05-12T10_59_09_arena8  \n",
       "63  video_2022-05-12T11_34_40_arena15  \n",
       "64  video_2022-05-12T11_34_40_arena16  \n",
       "65   video_2022-05-12T11_34_40_arena5  \n",
       "66   video_2022-05-12T11_34_40_arena6  \n",
       "\n",
       "[67 rows x 5 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aggression_df = pd.DataFrame()\n",
    "for condition in experiments.keys():\n",
    "    for h, experiment_path in enumerate(experiments[condition]):\n",
    "\n",
    "        experiment = os.path.basename(experiment_path).split('.')[0]\n",
    "        \n",
    "        print('Iteration:', h, '\\nExperiment:', experiment, '\\nCondition:', condition, '\\n')\n",
    "        \n",
    "        # Exclude experiments without copulation (since aggression is only observed during copulation).\n",
    "        annotation_video = annotations.read(experiment_path)\n",
    "        try:\n",
    "            copulation = annotation_video[0].events[0]\n",
    "        except IndexError:\n",
    "            continue\n",
    "        \n",
    "        aggression_events = list(filter(lambda event: event.time < (copulation.time + 18000), annotation_video[1].events)) # Consider aggression only during the first 5 minutes of copulation.\n",
    "        n_events = len(aggression_events)\n",
    "\n",
    "        # In case there is aggression, do the necessary calculations.\n",
    "        if n_events > 0:\n",
    "            \n",
    "            aggression_latency =  aggression_events[0].time - copulation.time\n",
    "            aggression_latency_mins = aggression_latency / (60 * FPS)\n",
    "            \n",
    "            ratio_frames = sum([aggression.duration for aggression in aggression_events]) / (5 * 60 * FPS)\n",
    "            ratio_bouts = n_events / 5\n",
    "            \n",
    "            aggression_data = pd.DataFrame({'has_aggression': True,\n",
    "                                            'ratio_frames': ratio_frames,\n",
    "                                            'ratio_bouts': ratio_bouts,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # If not, preset our dictionary with default values.\n",
    "        else:\n",
    "            aggression_data = pd.DataFrame({'has_aggression': False,\n",
    "                                            'ratio_frames': 0, \n",
    "                                            'ratio_bouts': 0,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # Concatenate all data together.\n",
    "        aggression_df = pd.concat([aggression_df, aggression_data], ignore_index=True)\n",
    "\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Outlier Detection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\t food_odor \n",
      "\n",
      "[7]\n",
      "Number data points considered outliers: 1\n",
      "Percent data points considered outliers: 3.03 %\n",
      "\n",
      "\t territory \n",
      "\n",
      "[43]\n",
      "Number data points considered outliers: 1\n",
      "Percent data points considered outliers: 2.941 %\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>ratio_bouts</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.012222</td>\n",
       "      <td>1.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.018500</td>\n",
       "      <td>1.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.017000</td>\n",
       "      <td>0.8</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.014611</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001833</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T10_59_09_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009833</td>\n",
       "      <td>1.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001222</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>True</td>\n",
       "      <td>0.016889</td>\n",
       "      <td>2.2</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>65 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  ratio_bouts  condition  \\\n",
       "0             True      0.012222          1.6  food_odor   \n",
       "1             True      0.018500          1.4  food_odor   \n",
       "2             True      0.017000          0.8  food_odor   \n",
       "3             True      0.000333          0.2  food_odor   \n",
       "4             True      0.014611          1.2  food_odor   \n",
       "..             ...           ...          ...        ...   \n",
       "62            True      0.001833          0.8  territory   \n",
       "63            True      0.009833          1.8  territory   \n",
       "64            True      0.001222          0.8  territory   \n",
       "65           False      0.000000          0.0  territory   \n",
       "66            True      0.016889          2.2  territory   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-11T11_12_38_arena10  \n",
       "1   video_2022-05-11T11_12_38_arena11  \n",
       "2   video_2022-05-11T11_12_38_arena13  \n",
       "3   video_2022-05-11T11_12_38_arena15  \n",
       "4   video_2022-05-11T11_12_38_arena16  \n",
       "..                                ...  \n",
       "62   video_2022-05-12T10_59_09_arena8  \n",
       "63  video_2022-05-12T11_34_40_arena15  \n",
       "64  video_2022-05-12T11_34_40_arena16  \n",
       "65   video_2022-05-12T11_34_40_arena5  \n",
       "66   video_2022-05-12T11_34_40_arena6  \n",
       "\n",
       "[65 rows x 5 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corrected_ratio_frames = pd.DataFrame()\n",
    "\n",
    "for condition in condition_order:\n",
    "\n",
    "    print('\\n\\t', condition, '\\n')\n",
    "\n",
    "    try:\n",
    "        dataset = aggression_df.query('condition==\"' + condition + '\"')['ratio_frames']\n",
    "\n",
    "        outlier_positions = helpers.check_outliers(dataset)\n",
    "        print(outlier_positions)\n",
    "\n",
    "        fresh_dataset = pd.DataFrame(helpers.remove_outliers(dataset, indices=outlier_positions))\n",
    "        fresh_dataset['condition'] = condition\n",
    "\n",
    "        corrected_ratio_frames = pd.concat([corrected_ratio_frames, fresh_dataset], axis=0)\n",
    "        \n",
    "    except ValueError as error:\n",
    "        print(error)\n",
    "\n",
    "aggression_df = aggression_df.loc[corrected_ratio_frames.index]\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Aggression Rate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>condition</th>\n",
       "      <th>ratio_frames</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.012222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.018500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.017000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.000333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.014611</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   condition  ratio_frames\n",
       "0  food_odor      0.012222\n",
       "1  food_odor      0.018500\n",
       "2  food_odor      0.017000\n",
       "3  food_odor      0.000333\n",
       "4  food_odor      0.014611"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_frames_df = aggression_df.copy()[['condition', 'ratio_frames']]\n",
    "ratio_frames_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\t territory \n",
      "\n",
      "Shapiro's Test: group 1 IS NOT normally distributed.\n",
      "D'Agostino's Test: group 1 IS NOT normally distributed.\n",
      "Shapiro's Test: group 2 IS NOT normally distributed.\n",
      "D'Agostino's Test: group 2 IS NOT normally distributed.\n",
      "Levene's Test for non-normally distributed samples:\n",
      "  p-value = 0.154793\n",
      "  All groups were sampled from populations with IDENTICAL variances.\n",
      "\n",
      "Mann-Whitney p-value: 0.1265861122790179 \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'territory': 0.1265861122790179}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_frames_pvalues = {}\n",
    "\n",
    "control = ratio_frames_df.query('condition==\"food_odor\"')['ratio_frames']\n",
    "\n",
    "for condition in condition_order[1:]:\n",
    "\n",
    "    print('\\n\\t', condition, '\\n')\n",
    "\n",
    "    try:\n",
    "        test = ratio_frames_df.query('condition==\"' + condition + '\"')['ratio_frames']\n",
    "\n",
    "        temp_values = {'control': control, 'test': test}\n",
    "\n",
    "        pvalue_condition = helpers.run_statistics(temp_values)\n",
    "\n",
    "        ratio_frames_pvalues[condition] = pvalue_condition\n",
    "        \n",
    "    except ValueError as error:\n",
    "        print(error)\n",
    "    \n",
    "ratio_frames_pvalues"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Effect Size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "territory\n",
      "Medium Effect: -0.5174825174825176 \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'territory': -0.5174825174825176}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_frames_effect_sizes = {}\n",
    "\n",
    "control = ratio_frames_df.query('condition==\"food_odor\"')['ratio_frames']\n",
    "\n",
    "for condition in condition_order[1:]:\n",
    "    \n",
    "    print(condition)\n",
    "    \n",
    "    test = ratio_frames_df.query('condition==\"' + condition +'\"')['ratio_frames']\n",
    "\n",
    "    median_diff = helpers.get_effect_size(control, test, method='median_diff')\n",
    "\n",
    "    ratio_frames_effect_sizes[condition] = median_diff\n",
    "    \n",
    "ratio_frames_effect_sizes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSU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1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Initialize figure.\n",
    "n_conditions = ratio_frames_df['condition'].nunique()\n",
    "figure, axis = plt.subplots(figsize=(1.25*n_conditions, 4))\n",
    "\n",
    "# Draw the boxplot.\n",
    "sns.boxplot(x='condition',\n",
    "            y='ratio_frames',\n",
    "            data=ratio_frames_df,\n",
    "            order=condition_order,\n",
    "            palette=['steelblue', '#5e6472'],\n",
    "            width=0.6,\n",
    "            showfliers=False,\n",
    "            boxprops={'edgecolor': INK},\n",
    "            medianprops={'color': INK},\n",
    "            whiskerprops={'color': INK},\n",
    "            capprops={'color': INK}\n",
    "           )\n",
    "\n",
    "# Draw the swarmplot.\n",
    "sns.swarmplot(x='condition',\n",
    "              y='ratio_frames',\n",
    "              data=ratio_frames_df,\n",
    "              order=condition_order,\n",
    "              palette=['steelblue', '#5e6472'],\n",
    "              linewidth=0.75,\n",
    "              edgecolor=INK\n",
    "             )\n",
    "\n",
    "# Figure and axes formatting.\n",
    "axis.set_xlabel('virgin females', labelpad=75)\n",
    "axis.set_xticklabels([''])\n",
    "axis.set_ylabel('Aggression Rate (%)')\n",
    "axis.set_ylim(0, 0.05)\n",
    "axis.set_yticks(np.arange(0, 0.05+0.001, 0.01))\n",
    "axis.set_yticklabels([int(y*100) for y in axis.get_yticks()])\n",
    "\n",
    "# Table definition.\n",
    "row1 = [str(ratio_frames_df.query('condition==\"'+condition+'\"').shape[0]) for condition in condition_order]\n",
    "row2 = ['Food\\nodour', 'Territory']\n",
    "cell_text = np.array([row1, row2])\n",
    "\n",
    "row_labels = ['n =', '']\n",
    "summary_table = axis.table(cellText= cell_text,\n",
    "                           cellLoc='center',\n",
    "                           rowLabels=row_labels,\n",
    "                           rowLoc='center',\n",
    "                           colLoc='center'\n",
    "                          )\n",
    "\n",
    "summary_table.auto_set_font_size(False)\n",
    "summary_table.set_fontsize(11)\n",
    "\n",
    "properties = summary_table.properties()\n",
    "table_cells = properties['children']\n",
    "for cell in table_cells:\n",
    "    cell.set_height(0.12)\n",
    "    cell.set_alpha(0)\n",
    "\n",
    "# Draw statistical result.\n",
    "for p, condition in enumerate(condition_order[1:]):\n",
    "    sig_height = 6 if (ratio_frames_pvalues.get(condition, 'NaN') == 'NaN') or (ratio_frames_pvalues.get(condition, 'NaN') >= 0.05) else 2\n",
    "    helpers.plot_stattest_result(ax=axis,\n",
    "                                 x1=p+1,\n",
    "                                 x2=p+1,\n",
    "                                 p_value=ratio_frames_pvalues.get(condition, 'NaN'),\n",
    "                                 y=0.046,\n",
    "                                 ticksize=0,\n",
    "                                 xytext=(0,sig_height),\n",
    "                                 fontsize=13,\n",
    "                                 color=INK,\n",
    "                                 connector_color=INK\n",
    "                                )\n",
    "\n",
    "# Saving parameters.\n",
    "filename = 'aggression_rate_first_5mins_territory_mating_pairs'\n",
    "plt.savefig(os.path.join(savepath, filename))\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
